package top.conangao.common.mybatisplus.autoconfig;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import top.conangao.common.mybatisplus.handler.CustomMetaObjectHandler;
import top.conangao.common.mybatisplus.handler.CustomTenantLineHandler;

/**
 * @author ConanGao
 * @description MybatisPlusAutoConfigure
 * @since 1.0
 **/
@AutoConfiguration
public class MybatisPlusAutoConfigure {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 多租户插件要在分页插件之前
        interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new CustomTenantLineHandler()));
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
    
    @Bean
    public CustomMetaObjectHandler myMetaObjectHandler() {
        return new CustomMetaObjectHandler();
    }
    
}
